#include "StdAfx.h"
#include "MaterialEditorWidget.h"

namespace Lit
{
	namespace Editor
	{
		namespace Material
		{
			EditorWidget::Ui::UiActions::UiActions()
			{
			}
			EditorWidget::Ui::UiActions::~UiActions()
			{}

			EditorWidget::Ui::Ui()
			{
				layout = NULL;
				textEdit = NULL;
				toolBar = NULL;
			}
			EditorWidget::Ui::~Ui()
			{}
		
			void EditorWidget::Ui::setupUi( QWidget * w )
			{
				if( !layout )
				{
					layout = new QVBoxLayout(w);
					textEdit = new TextEdit( w );
					toolBar = new QToolBar( w );
				
					layout->addWidget( toolBar );
					layout->addWidget( textEdit );
			
					w->setLayout( layout );

					setupToolbar(w);

					connectUi( w );
				}
			}
			void EditorWidget::Ui::connectUi(QWidget * w)
			{
				connect( textEdit, SIGNAL(modificationChanged(bool)), w, SIGNAL(modifiedStateChanged(bool)) );
			}
			void EditorWidget::Ui::setupToolbar( QWidget * w )
			{	
				if( !toolBar ) return;

				toolBar->setFixedHeight( 24 );
			}
			EditorWidget::EditorWidget( QWidget * parent ) 
				: QWidget( parent )
			{
				ui.setupUi(this);
			}
			EditorWidget::~EditorWidget(){}
			
			void EditorWidget::setText( const std::string &txt ){
				ui.textEdit->setPlainText( TO_QT(Ogre::StringUtil::replaceAll(txt, "\t", "    ")) );
			}
			std::string EditorWidget::getText() const{
				return FROM_QT(ui.textEdit->toPlainText());
			}

			void EditorWidget::setModified( bool state ){
				ui.textEdit->setModified( false );
				emit(modifiedStateChanged(state));
			}
			bool EditorWidget::isModified() const{
				return ui.textEdit->isModified();
			}

			EditorWidget::Ui* EditorWidget::getUi(){ return &ui; }
			const EditorWidget::Ui* EditorWidget::getUi() const{ return &ui; }

		};
	};
};